/*
 * StructureFactor.h
 *
 *  Created on: 29.07.2012
 *      Author: maikel
 */

#ifndef STRUCTUREFACTOR_H_
#define STRUCTUREFACTOR_H_

#include <fstream>
#include <string>
#include <vector>
#include <map>
#include "Atom.h"
#include "Eigen/Dense"

using namespace std;
using Eigen::Vector3d;
using gro::Atom;

namespace gro {

struct vector3d_comparer
{
   bool operator () (const Vector3d & t1, const Vector3d & t2) const
   {
	   return t1[0] < t2[0];
   }
};

class StructureFactor {
public:
	StructureFactor(string grofile);
	double operator()(Vector3d q);

	class ReadingError { };
	class ConsistencyError { };

private:
	void skip_line_until_valid_tilte();
	double sum(Vector3d q, const vector<Atom> &atoms);

	ifstream timestream;
	ofstream recovery;
	map<Vector3d, double, vector3d_comparer> cache;
	size_t N;
};

} /* namespace gro */
#endif /* STRUCTUREFACTOR_H_ */
